package com.ruoyi.user.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable()  // 关闭 CSRF 保护，视情况启用
            .authorizeRequests()
                .antMatchers("/user/login").permitAll()  // 允许访问登录页面
                .antMatchers("/user/*").permitAll()
                //.anyRequest().authenticated()  // 其他请求需要认证
            .and()
            .logout()
                .permitAll();  // 允许所有用户登出
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/resources/**");  // 忽略静态资源
    }
}
